from django.db import models

# Create your models here.
class Users(models.Model):
    username = models.CharField(max_length=50)
    password = models.CharField(max_length=100)
    phone = models.CharField(max_length=11)
    sex = models.CharField(max_length=1,null=True)
    age = models.CharField(max_length=3,null=True)
    head_url = models.CharField(max_length=100,null=True)
    status = models.IntegerField(default=0)
    addtime=models.DateTimeField(auto_now_add=True)
    email = models.CharField(max_length=100,null=True)
    class Meta:
        permissions = (
            ("show_Users", "查看用户列表权限"),
            ("create_Users", "添加用户信息权限"),
            ("edit_Users", "修改用户信息权限"),
            ("remove_Users", "删除用户信息权限"),
        )

# 商品的类别
class Cates(models.Model):
    #类别名
    name = models.CharField(max_length=50)
    #上级类别id
    upid = models.IntegerField()
    #类别等级路径
    paths = models.CharField(max_length=50)

    level = models.IntegerField()
    class Meta:
        permissions = (
            ("show_Cates", "查看分类列表权限"),
            ("create_Cates", "添加分类信息权限"),
            ("edit_Cates", "修改分类信息权限"),
            ("remove_Cates", "删除分类信息权限"),
        )


#商品
class Goods(models.Model):
    title = models.CharField(max_length=100)
    g_url = models.CharField(max_length=200)
    price = models.IntegerField()
    ordernum = models.IntegerField()
    ginfo = models.TextField()

    status = models.IntegerField(default=0)
    clicknum = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)

    cateid=models.ForeignKey(to="Cates",to_field="id")
    # 自定义 商品管理 权限
    class Meta:
        permissions = (
            ("show_Goods", "查看商品列表权限"),
            ("create_Goods", "添加商品信息权限"),
            ("edit_Goods", "修改商品信息权限"),
            ("remove_Goods", "删除商品信息权限"),
        )

# 购物车
class Car(models.Model):
    # id gid num uid
    gid=models.ForeignKey(to="Goods",to_field="id")
    num = models.IntegerField()
    uid=models.ForeignKey(to="Users",to_field="id")

# 用户的收货人地址
class Address(models.Model):
    # id   name phone sheng shi xian addinfo uid
    name = models.CharField(max_length=100)
    phone = models.CharField(max_length=100)
    sheng = models.CharField(max_length=100)
    shi = models.CharField(max_length=100)
    xian = models.CharField(max_length=100)
    addinfo = models.CharField(max_length=255)

    uid=models.ForeignKey(to="Users",to_field="id")

    isselect = models.IntegerField(default=0)

class Citys(models.Model):
    name = models.CharField(max_length=100)
    level = models.IntegerField()
    upid = models.IntegerField()

    class Meta():  
        db_table='citys'

# 订单
class Order(models.Model):
    # uid phone address    total wl pay uid status 
    uid = models.ForeignKey(to="Users",to_field="id") 
    phone = models.CharField(max_length=100)
    name = models.CharField(max_length=100)
    addinfo = models.CharField(max_length=255)
    total = models.IntegerField()
    # 0 顺丰 1 申通 2圆通
    wl = models.IntegerField()

    pay = models.IntegerField()

    status = models.IntegerField(default=0)

    createtime = models.DateTimeField(auto_now_add=True)

    paytime = models.DateTimeField(null=True)
    # 自定义 订单 权限
    class Meta:
        permissions = (
            ("show_Order", "查看订单列表权限"),
            ("create_Order", "添加订单信息权限"),
            ("edit_Order", "修改订单信息权限"),
            ("remove_Order", "删除订单信息权限"),
        )


class Orderinfo(models.Model):
    # gid  orderid num price
    orderid =  models.ForeignKey(to="Order",to_field="id")
    gid = models.ForeignKey(to="Goods",to_field="id")
    num = models.IntegerField()
    price = models.IntegerField()


